<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
	<head>
		<base href="<%=basePath%>">
		<meta charset="utf-8" />
		<title></title>
		<meta name="description" content="overview & stats" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<link rel="stylesheet" href="static/css/bootstrap.min.css" />
		<link rel="stylesheet" href="static/css/bootstrap-responsive.min.css" />
		<link rel="stylesheet" href="static/css/font-awesome.min.css" />
		<!-- 下拉框 -->
		<link rel="stylesheet" href="static/css/chosen.css" />
		<link rel="stylesheet" href="static/css/ace.min.css" />
		<link rel="stylesheet" href="static/css/ace-responsive.min.css" />
		<link rel="stylesheet" href="static/css/ace-skins.min.css" />
		
		<script type="text/javascript" src="static/1.9.1/jquery.min.js"></script>
		<!--提示框-->
		<script type="text/javascript" src="static/js/jquery.tips.js"></script>
		
<script type="text/javascript">
	$(top.hangge());
	$(document).ready(function(){
		if($("#operid").val()!=""){
			$("#username").attr("readonly","readonly");
			$("#username").css("color","gray");
		}
	});
	
	//保存
	function save(){
		if($("#roleid").val()==""){
			$("#roleid").tips({
				side:3,
	            msg:'选择角色',
	            bg:'#AE81FF',
	            time:2
	        });
			
			$("#roleid").focus();
			return false;
		}
		
		if($("#username").val()=="" || $("#username").val()=="此用户名已存在!"){
			$("#username").tips({
				side:3,
	            msg:'输入用户名',
	            bg:'#AE81FF',
	            time:2
	        });
			
			$("#username").focus();
			$("#username").val('');
			$("#username").css("background-color","white");
			return false;
		}else{
			$("#username").val(jQuery.trim($('#username').val()));
		}
		
		if($("#nickname").val()==""){
			$("#nickname").tips({
				side:3,
	            msg:'输入姓名',
	            bg:'#AE81FF',
	            time:3
	        });
			$("#nickname").focus();
			return false;
		}
		
		var myreg = /^(((13[0-9]{1})|159)+\d{8})$/;
		if($("#phonenumber").val()==""){
			if($("#phonenumber").val().length != 11 && !myreg.test($("#phonenumber").val())){
				$("#phonenumber").tips({
					side:3,
		            msg:'手机号格式不正确',
		            bg:'#AE81FF',
		            time:3
		        });
				$("#phonenumber").focus();
				return false;
			}
		}
		
		if($("#email").val()!=""){
			if(!ismail($("#email").val())){
				$("#email").tips({
					side:3,
		            msg:'邮箱格式不正确',
		            bg:'#AE81FF',
		            time:3
		        });
				$("#email").focus();
				return false;
			}
		}
		
		var username = $("#username").val();
		hasEmail(username);
	}
	
	function ismail(mail){
		return(new RegExp(/^(?:[a-zA-Z0-9]+[_\-\+\.]?)*[a-zA-Z0-9]+@(?:([a-zA-Z0-9]+[_\-]?)*[a-zA-Z0-9]+\.)+([a-zA-Z]{2,})+$/).test(mail));
	}
	
	//判断邮箱是否存在
	function hasEmail(username){
		var email = $("#email").val();
		var url = "newuser/hasEmail.do?email="+email+"&username="+username+"&tm="+new Date().getTime();
		$.get(url,function(data){
			if(data=="error"){
				$("#email").tips({
					side:3,
		            msg:'邮箱已存在',
		            bg:'#AE81FF',
		            time:3
		        });
				setTimeout("$('#email').val('')",2000);
			}else{
				$("#userForm").submit();
				$("#centerOfMainFrame").hide();
				$("#centerOfMainFrame2").show();
			}
		});
	}
</script>
	</head>
<body>
	<form action="<%=basePath%>/newuser/editUser.do" name="userForm" id="userForm" method="post">
		<input type="hidden" name="operid" id="operid" value="${pageData.operid }"/>
		<input type="hidden" name="currentselectorganid" id="currentselectorganid" value="${pageData.currentselectorganid }"/>
		<div id="centerOfMainFrame">
			<table>
				<c:if test="${fx != 'head'}">
					<tr>
						<td>所属机构：<input type="text" value="${pageData.organname }" title="机构名称" readonly="readonly" style="margin-left: 12px; "/></td>
					</tr>
				</c:if>
				<c:if test="${fx != 'head'}">
				<tr>
					<td>所属角色：
						<select name="roleid" id="roleid" data-placeholder="请选择角色" style="margin-left: 5px; ">
							<option value=""></option>
							<c:forEach items="${roleList}" var="role">
								<option value="${role.roleid }" <c:if test="${role.roleid == pageData.roleid }">selected</c:if>>${role.rolename }</option>
							</c:forEach>
						</select>
					</td>
				</tr>
				</c:if>
				<c:if test="${fx == 'head'}">
					<input name="roleid" id="roleid" value="${pageData.roleid }" type="hidden" />
				</c:if>
				
				<tr>
					<td>操作员名称：<input type="text" name="username" id="username" value="${pageData.username }" maxlength="32" placeholder="这里输入操作员名称" title="操作员名称" readonly="readonly" /></td>
				</tr>
				<tr>
					<td>操作员昵称：<input type="text" name="nickname" id="nickname"  value="${pageData.nickname }"  maxlength="32" placeholder="这里输入姓名" title="姓名" /></td>
				</tr>
				<tr>
					<td>手机号码：<input type="number" name="phonenumber" id="phonenumber"  value="${pageData.phonenumber }"  maxlength="32" placeholder="这里输入手机号" title="手机号" style="margin-left: 12px;"/></td>
				</tr>
				<tr>
					<td>邮件地址：<input type="email" name="email" id="email"  value="${pageData.email }" maxlength="32" placeholder="这里输入邮箱" title="邮箱" style="margin-left: 12px;"/></td>
				</tr>
				<c:if test="${operatorName == 'admin'}">
					<tr>
						<td>操作员状态：<select name="isvalid" title="状态">
							<option value="1" <c:if test="${pageData.isvalid == '1' }">selected</c:if> >正常</option>
							<option value="0" <c:if test="${pageData.isvalid == '0' }">selected</c:if> >冻结</option>
							</select>
						</td>
					</tr>
				</c:if>
				<tr>
					<td style="text-align: center;">
						<a class="btn btn-mini btn-primary" onclick="save();">保存</a>
						<a class="btn btn-mini btn-danger" onclick="top.Dialog.close();">取消</a>
					</td>
				</tr>
			</table>
		</div>
		<div id="centerOfMainFrame2" class="center" style="display:none"><br/><br/><br/><br/><img src="static/images/jiazai.gif" /><br/><h4 class="lighter block green"></h4></div>
	</form>
	
		<!-- 引入 -->
		<script type="text/javascript">window.jQuery || document.write("<script src='static/js/jquery-1.9.1.min.js'>\x3C/script>");</script>
		<script type="text/javascript" src="static/js/bootstrap.min.js"></script>
		<script type="text/javascript" src="static/js/ace-elements.min.js"></script>
		<script type="text/javascript" src="static/js/ace.min.js"></script>
		<script type="text/javascript" src="static/js/chosen.jquery.min.js"></script><!-- 下拉框 -->
		<script type="text/javascript">
		$(function() {
			//单选框
			$(".chzn-select").chosen(); 
			$(".chzn-select-deselect").chosen({allow_single_deselect:true}); 
			
			//日期框
			$('.date-picker').datepicker();
		});
		</script>
	
</body>
</html>